/*---------------------------------------------------------------------------
    ZaRan	-	A Totallly Automatic CFD Software
    Copyright (C) ,Since 2020
-------------------------------------------------------------------------------
License
    This file is part of ZaRan.

!	@file		gird.h
!	@brief	the purpose of this file.
!	@author	Chen Jie.
\*---------------------------------------------------------------------------*/
#include"../include/flux.h"
#include"Basic/include/CommonPara.h"

//void ConserveFlux::UpdateFromBasicVar(const double density, const double u, const double v, const double p)
//{
//  m_var[0] = density;
//  m_var[1] = density * u;
//  m_var[2] = density * v;
//  m_var[3] = p / (gama - 1) + 0.5 * density * (u * u + v * v);
//}
//
//
//void BaseVar::UpdFromConserveFlux(const ConserveFlux& flux)
//{
//  density_ = flux[0];
//  u_ = flux[1] / flux[0];
//  v_ = flux[2] / flux[0];
//  p_ = (gama - 1) * (flux[3] - 0.5 * density_ * (u_ * u_ + v_ * v_));
//}



VarList::VarList()
{
  variable_.resize(0);
}

VarList::VarList(vector<double>& var_list)
{
  variable_ = var_list;
}

VarList::VarList(const VarList& var_list)
{
  variable_ = var_list.variable_;
}

double VarList::variable(int i)const
{
  if (i < variable_.size())
    return variable_[i];
  else
    return NAN;
}

void VarList::SetVariable(vector<double>& variable_list)
{
  variable_ = variable_list;
}

void VarList::SetVariable(int i, double var_i)
{
  if (i < variable_.size())
    variable_[i] = var_i;
  else
    exit(0);
}

void VarList::SetToSameNumber(const double& number)
{
  for (int iVar = 0; iVar < variable_.size(); ++iVar)
  {
    variable_[iVar] = number;
  }
}

VarList VarList::operator+(const VarList& var_list)
{
  if (this->variable_.size() != var_list.variable_.size())
    exit(0);
  VarList var_out(*this);
  for (int iVar = 0; iVar < variable_.size(); ++iVar)
  {
    var_out.variable_[iVar] += var_list.variable_[iVar];
  }
  return var_out;
}

VarList VarList::operator-(const VarList& var_list)
{
  if (this->variable_.size() != var_list.variable_.size())
    exit(0);
  VarList var_out(*this);
  for (int iVar = 0; iVar < variable_.size(); ++iVar)
  {
    var_out.variable_[iVar] -= var_list.variable_[iVar];
  }
  return var_out;
}

VarList VarList::operator*(const double& number)
{
  VarList var_out(*this);
  for (int iVar = 0; iVar < variable_.size(); ++iVar)
  {
    var_out.variable_[iVar] *= number;
  }
  return var_out;
}

VarList VarList::operator/(const double& number)
{
  VarList var_out(*this);
  for (int iVar = 0; iVar < variable_.size(); ++iVar)
  {
    var_out.variable_[iVar] /= number;
  }
  return var_out;
}

VarList& VarList::operator+=(const VarList& var_list)
{
  if (this->variable_.size() != var_list.variable_.size())
    exit(0);
  for (int iVar = 0; iVar < variable_.size(); ++iVar)
  {
    this->variable_[iVar] += var_list.variable_[iVar];
  }
  return *this;
}

VarList& VarList::operator-=(const VarList& var_list)
{
  if (this->variable_.size() != var_list.variable_.size())
    exit(0);
  for (int iVar
      = 0; iVar < variable_.size(); ++iVar)
  {
    this->variable_[iVar] -= var_list.variable_[iVar];
  }
  return *this;
}

VarList& VarList::operator*=(const double& number)
{
  for (int iVar = 0; iVar < variable_.size(); ++iVar)
  {
    this->variable_[iVar] *= number;
  }
  return *this;
}

VarList& VarList::operator/=(const double& number)
{
  for (int iVar = 0; iVar < variable_.size(); ++iVar)
  {
    this->variable_[iVar] /= number;
  }
  return *this;
}
